home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / SPIES.DOC < prev    next >
Text File  |  1987-05-16  |  12KB  |  203 lines

  1. 615 796 2640
  2. This file, SPIES.DOC, is the documentation for the 1.0 versions of the two
  3. programs SPY.COM, and SPY'.COM and also the accompanying source files SPY.ASM
  4. and SPY'.ASM.
  5.  
  6. The programs were written for the TSR Seminar/Tutor section of the Microsoft
  7. forum of CompuServe.  They are shareware programs with a $1 minimum requested
  8. donation.  If you like the programs and/or the ideas presented in the source
  9. code I would be pleased if you would send me a monetary note of thanks.  What
  10. do you get for your $1?  Not much to be sure.  In fact each $1 that you send
  11. will be a vote for an enhanced version of a SPY program that will be written
  12. contingent upon the number of $1's received.  (It too would be shareware and
  13. source code would be made available to those sending in payments).
  14.  
  15. You may send donations to:
  16.  
  17.    Charles Lazo III
  18.    P. O. Box 2312
  19.    Hohenwald, TN 38462
  20.  
  21. My CompuServe user ID is 72210,17.
  22.  
  23. The object of these programs is to demonstrate two methods that allow a program
  24. to detect if it has been loaded as a TSR before and if so to optionally pass
  25. parameters to the previous load.  In addition to making the programs as simple
  26. as possible it was also desired to make them useful in their own right.
  27. Whether I have been successful in this endeavor will be up to you to decide.
  28.  
  29. Both SPY.COM and SPY'.COM behave in exactly the same way as far as the user is
  30. concerned (except, of course, for the copyright and syntax notices).  Running
  31. the SPY program without parameters (or by making an error in syntax) you will
  32. see:
  33.  
  34. SPY Copyright (C) 1987 by Charles Lazo III, v1.0
  35.  
  36. SPY syntax:  SPY xxxx:yyyy L zzz
  37.  
  38. Where xxxx, and yyyy are hexadecimal numbers up to four digits in length and
  39. zzz is a one to three digit hexadecimal number.  SPY will monitor the segment-
  40. offset region xxxx:yyyy for a length of zzz bytes and report to the user with a
  41. number of beeps equal to the number of bytes changed in that region if and when
  42. any are changed.
  43.  
  44. The method of parameter setting for SPY is the same as one of the methods of
  45. specifying a range for DEBUG, i.e., segment:offset L size.  After the parameter
  46. string you may optionally place comments on the same line by preceding them with
  47. a semicolon (may be useful for SPY in batch files).  The parameter string may be
  48. entered in any combination of upper and lower case, and tabs or spaces may be
  49. sprinkled liberally within it except that hex numbers may not be broken up.
  50.  
  51. The length of the spy region has been arbitrarily limited to three hex digits.
  52. This allows for up to 4095 bytes to be monitored at once for changes while SPY
  53. is loaded.  This maximum value also determines how much memory that SPY will
  54. reserve for the spy buffer, an area of memory that will contain a copy of the
  55. region of memory to be spied upon.  Each time a change occurs in the spy region
  56. chosen by the user on the command line SPY will increment a counter and update
  57. its copy of the region which it uses for comparison.  This action takes place
  58. in a modified interrupt 8 (clock) handler.  In the new int 8 routine if this
  59. counter is non zero, then the speaker will be turned on and the counter will be
  60. decremented.  If the speaker is on then it is turned off at the next int 8.
  61. A delay counter is set after each beep and is decremented thereafter at each
  62. int 8 tick.  Another beep will not occur until the delay counter is decremented
  63. to zero.  Thus the beeps emitted by SPY occur at intervals which depend upon
  64. the value set into the delay counter.  The maximum size of the spy region and
  65. the value of the delay interval can be changed if the constants which control
  66. them are altered in the SPY.ASM file and the program is reassembled, relinked
  67. and passed through the EXE2BIN program.  One more thing that can be easily
  68. changed is the frequency of the tone emitted by SPY.  The default frequency is
  69. just about 2,000 hertz.
  70.  
  71. Setting SPY's sights upon a volatile region can become distracting so it is
  72. welcome knowledge that you can shut it up merely by pointing it to another
  73. region of memory.  I suggest pointing it to ROM, e.g., SPY F800:0 L1.  Thus
  74. to be explicit about the nature of SPY's operation after being loaded once
  75. before:  SPY detects a previous load of itself as a TSR, and if there were any
  76. parameters on the command line of the current load, then the code in spy will
  77. pass these parameters to the code of the previous load and they will be acted
  78. upon as if SPY is being loaded for the first time.  (This is why SPY will save
  79. a buffer of 4095 bytes [by default] even if you only ask for the monitoring of
  80. a single byte.)
  81.  
  82. Keeping the program simple has lead to a number of compromises in its operation.
  83. One undesirable result is segment wrap around.  If you were to run SPY as:
  84.  
  85.                            SPY 0:ff00 L 200,
  86.  
  87. then instead of monitoring the 512 bytes from ff0:0 to ff0:200 as you might
  88. expect, you would instead be keeping tabs on the 256 bytes from ff0:0 to ff0:ff
  89. and also the 256 bytes at the top of this segment from 0:0 to 0:ff.  Instead
  90. enter this as:
  91.  
  92.                            SPY ff0:0 L 200.
  93.  
  94. While DEBUG will flag this sort of carelessness with an error, SPY will accept
  95. it and wrap the segment without complaint.
  96.  
  97. Before I begin comment on the details of the source code that allows sensing a
  98. previous program load I would like to mention a few of the discoveries that I
  99. have made snooping around with SPY.  There is a 16 byte region in the DOS data
  100. section of memory called the ICA (Intra-Application Communications Area).  Not
  101. many programs use this region and one good application of SPY is to monitor it
  102. to determine which programs do use it.  I was surprised to discover that BRIEF,
  103. the editor which I am using to put this stuff together, uses this region.  Why
  104. I don't know.  To monitor this region enter SPY 0:4f0L10.  Another good place to
  105. point SPY is the interrupt table:  SPY 0:0l400.  I have noticed while monitoring
  106. this region that even though interrupt vectors are four bytes long I sometimes
  107. count a number of changes which is not divisible by four.  I dono why.  The most
  108. interesting discovery so far, however, has been the location of a byte in a
  109. section of memory used by DOS.  I suppose it is in the non transient portion of
  110. COMMAND.  The location is 291:1a7 in my PC DOS ver 3.20.  What is interesting is
  111. that while SPY is pointed at this single byte and DOS is at the DOS prompt every
  112. keypress that places a printable character on the screen also elicits a beep
  113. from SPY.  The byte is changed very many times for a long display such as a
  114. directory listing or a file typed to the screen.
  115.  
  116. SPY.ASM and SPY'.ASM differ in only one respect except for the near universal
  117. replacement of SPY with SPY' in the SPY'.ASM program.  This is the method that
  118. the two programs use to detect previous loads of themselves.  The detection done
  119. by SPY is carried out entirely in the routine named set_es while for SPY' it is
  120. done in both set_es and newint16h (a routine chained into the ROM BIOS keyboard
  121. interrupt vector).  Both programs use a set of three data values, key1, key2,
  122. and key3 that are words which are set into specific offsets when the program
  123. loads for the first time and becomes a TSR.  The idea of detection in each case
  124. is to search locations in memory for the three key values in the relative
  125. locations in which they are expected to be found.  SPY uses a brute force method
  126. that looks at every paragraph prior to the current value of the code segment for
  127. the presence of the keys.  The value of key1 is the two byte op code for the
  128. instruction int 20h which is found at offset 0 of every PSP.  It was chosen
  129. because if all of the keys were at offsets following location 100h in the code
  130. segment, then SPY could fail in its attempt to find itself in memory because it
  131. might mistake a set of data in a cache or in the buffers of DOS as a prior load
  132. if itself.  SPY' uses the routine newint16h to add a new function to the ROM
  133. BIOS keyboard interrupt int 16h.  The set_es routine invokes the int 16h with
  134. the function number ah = 77h.  When SPY' has not b